using System;
using Common;
using Entity;
using Mapper;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace CardGameObject.Common
{
    public class ItemDisplay : MonoBehaviour
    {
        public Image ItemImage;
        public TextMeshProUGUI ItemText;
        public ItemTypeEnum ItemType;

        public int Value { get; set; }

        public void SetTextContent(int value)
        {
            ItemText.text = value.ToString();
        }

        public void SetImageContent(Sprite sprite)
        {
            ItemImage.sprite = sprite;
        }

        public void ChangeValue(int value)
        {
            Value += value;
            SetTextContent(Value);
        }

        private void Start()
        {
            UserMapper userMapper = new UserMapper();
            // 改为当前登录的用户信息
            User user = userMapper.GetUserById(1);
            if (ItemType == ItemTypeEnum.COIN)
            {
                ItemText.text = user.Coin.ToString();
                Value = user.Coin;
            }
            else if (ItemType == ItemTypeEnum.DUST)
            {
                ItemText.text = user.Dust.ToString();
                Value = user.Dust;
            }
            userMapper.CloseConnection();
        }
    }
}
